package model.potentialField;

import java.awt.Point;

public class ObstacleLayer extends Layer{
	protected int repulsion;
	
	public ObstacleLayer(int width, int height, int repulsion){
		super(width, height);
		this.repulsion = repulsion;
	}	
	
	public ObstacleLayer(int width, int height){
		this(width,height,3);
	}
	
	public void calculatePf(){
		// Set all obstacles in the potential Field
		clear(potentialField);
		for(int i = 0; i < this.width; i++){
			for(int j = 0; j < this.height; j++){
				// Set all obstacles
				for(int k = 0; k < this.elements.size(); k++){
					Point point = this.elements.get(k);
					if(Math.abs(point.x - i) < repulsion && Math.abs(point.y - j) < repulsion){
						if(Math.abs(point.x - i) < Math.abs(point.y - j) ){
							potentialField[i][j] -= Math.abs(point.y - j);	
						}else{
							potentialField[i][j] -= Math.abs(point.x - i);
						}
					}
				}
			}
		}
	}

}
